<#assign ctx = request.contextPath />
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>分步表单</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${ctx}/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctx}/css/public.css" media="all">
    <link rel="stylesheet" href="${ctx}/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="${ctx}/js/lay-module/step-lay/step.css" media="all">
    <style>
        .layui-form-label{
            width:85px!important;
        }
        .layui-input{
            width: 99%!important;
        }
        .pageDetails{
            display: none;
        }
        .contentDetails{
            display: none;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-fluid">
            <div class="layui-card">
                <div class="layui-card-body" style="padding-top: 40px;">
                    <div class="layui-carousel" id="stepForm" lay-filter="stepForm" style="margin: 0 auto;">
                        <div carousel-item>
                            <div>
                                <form class="layui-form" style="margin: 0 auto;max-width: 800px;padding-top: 40px;">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">网站前缀</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="prefix" placeholder="请填写网站的前缀" class="layui-input"  required />

                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">目录页地址</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="catalogueUrl" placeholder="请填写目录地址" value="" class="layui-input" lay-verify="requireds" required>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">返回值类型</label>
                                        <div class="layui-input-block">
                                            <input type="radio" name="resultType" value="html" title="html" checked>
                                            <input type="radio" name="resultType" value="json" title="json" disabled>
                                            <i class="fa fa-exclamation-circle" id="resultType-tips"
                                               onmouseover="showTips('暂时只支持html格式',this)"
                                               onmouseleave="closeTips()"></i>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">是否分页： </label>
                                        <div class="layui-input-block">
                                            <input type="checkbox" value="1" name="isPaginate" lay-skin="switch" lay-filter="switchIsPaginate" lay-text="ON|OFF">
                                            <i class="fa fa-exclamation-circle" id="isPaginate-tips"
                                               onmouseover="showTips('查看目录是否有分页',this)"
                                               onmouseleave="closeTips()"></i>
                                        </div>
                                    </div>
                                    <div class="layui-form-item pageDetails">
                                        <label class="layui-form-label">目录内容范围</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="pageTag" placeholder="请填写标签值" value="" class="layui-input" required>
                                        </div>
                                        <div class="layui-input-inline">
                                            <select name="pageAttribute">
                                                <option value="">请选择属性</option>
                                                <option value="class">class</option>
                                                <option value="name" >name</option>
                                                <option value="id" >id</option>
                                            </select>
                                        </div>
                                        <div class="layui-input-inline">
                                            <input type="text" name="pageAttributeValue" placeholder="请填写属性值" value="" class="layui-input" required>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">章节内容范围</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="chapterTag" placeholder="请填写标签值" value="" class="layui-input" required>
                                        </div>
                                        <div class="layui-input-inline">
                                            <select name="chapterAttribute">
                                                <option value="">请选择属性</option>
                                                <option value="class">class</option>
                                                <option value="name" >name</option>
                                                <option value="id" >id</option>
                                            </select>
                                        </div>
                                        <div class="layui-input-inline">
                                            <input type="text" name="chapterAttributeValue" placeholder="请填写属性值" value="" class="layui-input" required>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <div class="layui-input-block">
                                            <button class="layui-btn" lay-submit lay-filter="formStep">
                                                &emsp;下一步&emsp;
                                            </button>
                                            <button class="layui-btn" type="button" lay-submit lay-filter="formStep-test">
                                                测试
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div>
                                <form class="layui-form" style="margin: 0 auto;max-width: 800px;padding-top: 40px;">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">正文内容范围</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="contentTag" placeholder="请填写标签值" value="" class="layui-input" required>
                                        </div>
                                        <div class="layui-input-inline">
                                            <select name="contentAttribute">
                                                <option value="">请选择属性</option>
                                                <option value="class">class</option>
                                                <option value="name" >name</option>
                                                <option value="id" >id</option>
                                            </select>
                                        </div>
                                        <div class="layui-input-inline">
                                            <input type="text" name="contentAttributeValue" placeholder="请填写属性值" value="" class="layui-input" required>
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">是否分页： </label>
                                        <div class="layui-input-block">
                                            <input type="checkbox" value="1" name="" lay-skin="switch" lay-filter="switchIsPaginate2" lay-text="ON|OFF">
                                            <i class="fa fa-exclamation-circle" id="switchIsPaginate-tips"
                                               onmouseover="showTips('确认正文是否有下一页',this)"
                                               onmouseleave="closeTips()"></i>
                                        </div>
                                    </div>
                                    <div class="layui-form-item contentDetails">
                                        <label class="layui-form-label">正文分页类型</label>
                                        <div class="layui-input-block">
<#--                                            <input type="radio" name="contentPaginateType" value="html" title="html" checked>-->
<#--                                            <input type="radio" name="contentPaginateType" value="json" title="json" disabled>-->
<#--                                            <i class="fa fa-exclamation-circle"></i>-->
                                        </div>
                                    </div>
                                    <div class="layui-form-item contentDetails">
                                        <label class="layui-form-label">正文分页规则</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="contentPaginateRules" placeholder="例如：http://cgzb.dlnu.edu.cn/dlnustatic/hwjggs/index_${r'${ID}'}.html" class="layui-input"  required />
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">无关文本</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="irrelevantText" placeholder="例如：</p><br><br>本章未完，点击下一页继续阅读<p>" class="layui-input"  required />
                                        </div>
                                    </div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">输出路径</label>
                                        <div class="layui-input-block">
                                            <input type="text" name="outputPath" placeholder="例如：D:\Desktop" class="layui-input"  required />
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <div class="layui-input-block">
                                            <button type="button" class="layui-btn layui-btn-primary pre">上一步</button>
                                            <button type="button" class="layui-btn" lay-submit lay-filter="formStep-test2">
                                                测试
                                            </button>
                                            <button class="layui-btn" lay-submit lay-filter="formStep2">
                                                &emsp;执行&emsp;
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div>
                                <div style="text-align: center;margin-top: 90px;">
                                    <i class="layui-icon layui-circle"
                                       style="color: white;font-size:30px;font-weight:bold;background: #52C41A;padding: 20px;line-height: 80px;">&#xe605;</i>
                                    <div style="font-size: 24px;color: #333;font-weight: 500;margin-top: 30px;">
                                        执行成功
                                    </div>
                                    <div style="font-size: 14px;color: #666;margin-top: 20px;">请查看输出路径</div>
                                </div>
                                <div style="text-align: center;margin-top: 50px;">
                                    <button class="layui-btn next">继续采集</button>
                                    <button class="layui-btn layui-btn-primary">查看</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <hr>
                    <div style="color: #666;margin-top: 30px;margin-bottom: 40px;padding-left: 30px;">
                        <h3>说明</h3><br>
                        <h4>目录</h4>
                        <p>如果需要，这里可以放一些常见问题说明。</p>
                        <br><h4>正文</h4>
                        <p>如果需要，这里可以放一些常见问题说明。</p>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>
<script src="${ctx}/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="${ctx}/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use([ 'form', 'step'], function () {
        var $ = layui.$,
            form = layui.form,
            step = layui.step;

        step.render({
            elem: '#stepForm',
            filter: 'stepForm',
            width: '100%', //设置容器宽度
            stepWidth: '950px',
            height: '500px',
            stepItems: [{
                title: '配置章节列表'
            }, {
                title: '配置正文列表'
            }, {
                title: '采集文本'
            }]
        });


        form.on('submit(formStep)', function (data) {
            step.next('#stepForm');
            return false;
        });

        form.on('submit(formStep-test)', function (data) {
            var loadIndex;
            $.ajax({
                url: "${ctx}" + "/api/v1/crawl/test",
                data: $(".layui-form").serialize(),
                type: "get",
                dataType: "json",
                beforeSend : function (){
                    loadIndex = layer.load(1);
                },
                success: function (response) {
                    layer.close(loadIndex);
                    layer.msg("解析成功，分页数据：" + response.data.toString());
                    return false;
                },
                error: function () {
                    layer.close(loadIndex);
                    layer.msg("解析失败，请开启详细配置继续测试。如果仍然失败，请上传问题或联系作者探讨。");
                    return false;
                }
            })
        });

        form.on('submit(formStep-test2)', function (data) {
            var loadIndex;
            $.ajax({
                url: "${ctx}" + "/api/v1/crawl/test",
                data: $(".layui-form").serialize(),
                type: "get",
                dataType: "json",
                beforeSend : function (){
                    loadIndex = layer.load(1);
                },
                success: function (response) {
                    layer.close(loadIndex);
                    layer.msg("解析成功，分页数据：" + response.data.toString());
                    return false;
                },
                error: function () {
                    layer.close(loadIndex);
                    layer.msg("解析失败");
                    return false;
                }
            })
        });

        form.on('submit(formStep2)', function (data) {
            step.next('#stepForm');
            return false;
        });

        form.on('switch(switchIsPaginate)',function (data) {
            var elem = data.elem; // 获得 checkbox 原始 DOM 对象
            var checked = elem.checked; // 获得 checkbox 选中状态
            if (checked) {
                $(".pageDetails").show();
            } else {
                $(".pageDetails").hide();
            }
        })
        form.on('switch(switchIsPaginate2)',function (data) {
            var elem = data.elem; // 获得 checkbox 原始 DOM 对象
            var checked = elem.checked; // 获得 checkbox 选中状态
            if (checked) {
                $(".contentDetails").show();
            } else {
                $(".contentDetails").hide();
            }
        })

        $('.pre').click(function () {
            step.pre('#stepForm');
        });

        $('.next').click(function () {
            step.next('#stepForm');
        });
    });
    function showTips(msg, obj) {
        layer.tips('' + msg, '#' + obj.id, {tips: [1, 'black']});
    }

    function closeTips() {
        layer.closeAll('tips');
    }
</script>
</body>
</html>